package com.example.wangandroid.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.LogUtils
import com.example.common.ListAircle
import com.example.common.TreeClass
import com.example.wangandroid.R


class TreeAdapterList(private var data: ListAircle): RecyclerView.Adapter<TreeAdapterList.ViewHolder>() {


    class ViewHolder(itemView: View):RecyclerView.ViewHolder(itemView){
        var title:TextView = itemView.findViewById(R.id.tv_name)
        var author:TextView = itemView.findViewById(R.id.tv_author)
        var time :TextView= itemView.findViewById(R.id.tv_time)
        var dec:TextView=itemView.findViewById(R.id.tv_dec)
        var ll: LinearLayout = itemView.findViewById(R.id.ll)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
       val view = LayoutInflater.from(parent.context).inflate(R.layout.treelist_item,parent,false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int {
        return data.data.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val userPoint = data.data.datas[position]
        holder.title.text = userPoint.title
        holder.author.text = userPoint.shareUser
        holder.dec.text = userPoint.superChapterName
        holder.time.text = userPoint.niceDate
        holder.ll.setOnClickListener {
            ARouter.getInstance().build("/app/article")
                .withString("url",userPoint.link)
                .navigation();
        }
    }

    fun setData(it: ListAircle?) {
        if (it != null) {
            data = it
        }
    }

}